/*
 * Copyright (c) 2010 CCX(China) Co.,Ltd. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of
 * CCX(China) Co.,Ltd. ("Confidential Information").
 * It may not be copied or reproduced in any manner without the express 
 * written permission of CCX(China) Co.,Ltd.
 *
 * Author: zhaosj
 * Date: 2010-5-10 下午01:23:53
 */
package com.filesystem;

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;

import jxl.Workbook;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;

public class FileTest {
	public FileTest() {
	}

	public static void main(String[] args) {
		FileOutputStream out = null;
		FileOutputStream outSTr = null;
		BufferedOutputStream Buff = null;
		FileWriter fw = null;
		int count = 100000;// 写文件行数
		try {
			
//			
//			//String path="\\\\10.0.1.23\\share\\aaa.txt";
//			String path="\\\\10.0.1.24 \\public_share\\aaa.txt";
//			File f = new File(path);
//			System.out.println(f.exists());
//			


			

			/*//效率高
			BufferedWriter bw = new BufferedWriter(new FileWriter("c:/abc.txt")) ;
			long begin4 = System.currentTimeMillis() ;
			for (int i = 0; i < count; i++) {
				bw.write("row,value\r\n");
			}
			bw.close() ;
			long end4 = System.currentTimeMillis();
			System.out.println("BufferedWrite 执行耗时："+ (end4 - begin4) + "毫秒");
			*/
			
			String file = "C:\\financialTest\\20080303\\100\\free\\weight\\20080303.xls" ;
			Workbook wb = Workbook.getWorkbook(new File(file)) ;
			WritableWorkbook wwb = Workbook.createWorkbook(new File(file) ,wb) ;
			WritableSheet sheet  =  wwb.getSheet("K=30");
			jxl.write.Number number = null ;
			
			BufferedReader in = new BufferedReader(new FileReader("C:\\guochun\\weight_20080303_100.txt")) ;
			String line = null ;
			
			ArrayList<double[]> Data = new ArrayList<double[]>();
			while ((line = in.readLine()) != null) {
				String[] sa = line.split("--");
				double[] data = new double[sa.length];
				Data.add(data);
				for (int i = 0; i < sa.length; i++) {
					data[i] = Double.parseDouble(sa[i]);
				}
			}
			
			System.out.println("data length = "+Data.size());
			for (int i = 0 ; i < Data.size() ; i++)
			{
				double[] d = Data.get(i) ;
				for(int j = 0 ; j < d.length ; j++)
				{
					number = new jxl.write.Number(13, i, d[1]) ; 
					sheet.addCell(number) ;
					System.out.println(d[j]);
				}
			}
			
			wwb.write() ;
			
			wwb.close() ; 
			wb.close() ;
	
			
//			// 效率次高
//			fw = new FileWriter("C:/add2.txt");
//			long begin3 = System.currentTimeMillis();
//			for (int i = 0; i < count; i++) {
//				fw.write("FileWriter 测试java 文件操作\r\n");
//			}
//			fw.close();
//			long end3 = System.currentTimeMillis();
//			System.out.println("FileWriter执行耗时:" + (end3 - begin3) + " 豪秒");
//
//			
//			
//			
//			// 效率一般
//			outSTr = new FileOutputStream(new File("C:/add0.txt"));
//			Buff = new BufferedOutputStream(outSTr);
//			long begin0 = System.currentTimeMillis();
//			for (int i = 0; i < count; i++) {
//				Buff.write("BufferedOutputStream 测试java 文件操作\r\n".getBytes());
//			}
//			Buff.flush();
//			Buff.close();
//			long end0 = System.currentTimeMillis();
//			System.out.println("BufferedOutputStream执行耗时:" + (end0 - begin0)
//					+ " 豪秒");
//
//			
//			
//			// 效率低
//			out = new FileOutputStream(new File("C:/add.txt"));
//			long begin = System.currentTimeMillis();
//			for (int i = 0; i < count; i++) {
//				out.write("FileOutputStream 测试java 文件操作\r\n".getBytes());
//			}
//			out.close();
//			long end = System.currentTimeMillis();
//			System.out.println("FileOutputStream执行耗时:" + (end - begin) + " 豪秒");
//			
			
			

		} catch (Exception e) {
			
			e.printStackTrace();
			
		} finally {
			try {
				if (fw != null)
					fw.close();
				if (Buff != null)
					Buff.close();
				if (outSTr != null)
					outSTr.close();
				if (out != null)
					out.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
}
